<?php

class omeanalysts_ome_expressreconciliation extends eccommon_analysis_abstract implements eccommon_analysis_interface
{
    public $type_options = array(
        'display' => 'true',
    );

    public $graph_options = array(
        'hidden' => true,
    );

    public function set_params($params)
    {
        $this->_params = $params;

        return $this;
    }//End Function


    public function get_type()
    {
        
        
        $sql = 'SELECT name FROM sdb_ome_dly_corp where AxTyoe != \'200000292\' order by name';
        $logi_name = kernel::database()->select($sql);
        $logi_names[0] = '全部';
        foreach ($logi_name as $key => $val) {
            $logi_names[$val['name']] = $val['name'];
        }
        $logi_names = array_unique($logi_names);
        //add by ldward 根据判断过滤权限

         if($_POST['branch_ids']){
            $sql = 'SELECT distinct  name FROM sdb_ome_branch WHERE branch_id IN (\''.implode('\',\'', $_POST['branch_ids']).'\')';
            $branch_ids = kernel::database()->select($sql);
        }else{
            $sql = 'SELECT distinct  name FROM sdb_ome_branch';
            $branch_ids = kernel::database()->select($sql);
        }
         //$branch_data[0]='全部';
        foreach ($branch_ids as $key => $val) {
            $branch_data[$val['name']] = $val['name'];
        }
        $branch_data = array_unique($branch_data);
        
        $return = array(
            'logi_name' => array(
                'lab' => '物流公司',
                'data' => $logi_names,
                'type' => 'select',
            ),
            'branch' => array(
                'lab' => '仓库',
                'data' => $branch_data,
                'type' => 'select',
            ),
            
            'logi_no' => array(
                'lab' => '物流单号',
                'type' => 'text',
            ),
            
             
            
            'net_weightdy' => array(
                'lab' => '重量大于',
                'type' => 'text',
               
            ),
            'net_weightxy' => array(
                'lab' => '重量小于',
                'type' => 'text',
               
            ),

        );

        return $return;
    }

    public function headers()
    {
        parent::headers();
        $this->_render->pagedata['typeData'] = $this->get_type();
        $type_selected = array(
            'logi_name' => $this->_params['logi_name'],
            'branch' => $this->_params['branch'],
            'logi_no' => $this->_params['logi_no'],
            'conditions' => $this->_params['conditions'],
            'net_weightdy' => $this->_params['net_weightdy'],
            'net_weightxy' => $this->_params['net_weightxy'],
            
        );
        $this->_render->pagedata['type_selected'] = $type_selected;
    }

    public function ext_detail(&$detail)
    {
        $params = $this->_params;
        $filter = array(
            'time_from' => $params['time_from'],
            'time_to' => $params['time_to'],
        );
        
    }

    public function finder()
    {

        $_GET['filter']['from'] = array(
            'type_id' => $_POST['type_id'],
            'time_from' => $params['time_from'],
            'time_to' => $params['time_to'],
        );
        $_extra_view = array(
            'omeanalysts' => 'ome/delivery/delivery_view.html',
        );

        $this->set_extra_view($_extra_view);

        $actions['export'] = array(
            'label' => app::get('omeanalysts')->_('生成报表<script>if($$(".finder-list").getElement("tbody").get("html") == "\n" || $$(".finder-list").getElement("tbody").get("html") == "" ){$$(".export").set("href","javascript:;").set("onclick", "alert(\"没有可以生成的数据\")");}else{$$(".export").set("href",\'index.php?app=omeanalysts&ctl=ome_delivery&act=expressreconciliation&action=export\');}</script>'),
            'class' => 'export',
            'icon' => 'add.gif',
            'href' => 'index.php?app=omeanalysts&ctl=ome_delivery&act=expressreconciliation&action=export',
            'target' => '{width:600,height:300,title:\'生成报表\'}'
        );
        // $actions['btnax'] = array(
        //     'label' => "过数",
        //     'icon' => 'add.gif',
        //     'submit' => 'index.php?app=wms&ctl=admin_deliverynote&act=doConfirm'
        // );
        $user = kernel::single('desktop_user');
        if ($user->has_permission('order_export') && $servicelist = kernel::servicelist('ietask.service.actionbar')) {
            foreach ($servicelist as $object => $instance) {
                if (method_exists($instance, 'getOmeanalystsDelivery')) {
                    $actionBars = $instance->getOmeanalystsDelivery();
                    foreach ($actionBars as $actionBar) {
                        $actions[] = $actionBar;
                    }
                }
            }
        }
        #增加报表导出权限
        
        $is_export = kernel::single('desktop_user')->has_permission('expressreconciliation_export');
        if (!$is_export) {
            unset($actions['export']);
        }

        $params = array(
            'actions' => $actions,
            'title' => app::get('omeanalysts')->_('快递对账报表'), 
            'use_buildin_recycle' => false,
            'use_buildin_selectrow' => false,
        );
        $params['op_id'] = $_POST['op_id'];

        return array(
            'model' => 'omeanalysts_mdl_ome_expressreconciliation',
            'params' => $params,
        );
    }
}